package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.DeviceInfoService;
import com.yunhai.model.entity.dms.DmsDeviceInfoEntity;
import com.yunhai.model.vo.dms.DmsDeviceInfoQuery;
import com.yunhai.model.vo.dms.DmsDeviceInfoVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/deviceInfo")
public class DeviceInfoController {

	@Resource
	private DeviceInfoService deviceInfoService;

	/**
	 * 获取 DeviceInfo 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getDeviceInfoPagination(PaginationVo paginationVo, DmsDeviceInfoQuery dmsDeviceInfoQuery ) throws Exception {
		IPage page = deviceInfoService.getDeviceInfoPagination(paginationVo, dmsDeviceInfoQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 DeviceInfo 所有数据
	 */
	@GetMapping("/allList")
	public Ret getDeviceInfoAllList( DmsDeviceInfoQuery dmsDeviceInfoQuery ) throws Exception {
		List<DmsDeviceInfoEntity> list = deviceInfoService.getDeviceInfoAllList( dmsDeviceInfoQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 DeviceInfo 详情
	 */
	@GetMapping("/{id}")
	public Ret getDeviceInfoDetailById(@PathVariable Long id) throws Exception {

	    DmsDeviceInfoEntity dmsDeviceInfoEntity = deviceInfoService.getDeviceInfoDetail(id);
		return Ret.ok(dmsDeviceInfoEntity);
	}

	/**
	 * 新增 DeviceInfo
	 * */
	@PostMapping("")
	public Ret addDeviceInfo(@RequestBody DmsDeviceInfoVo dmsDeviceInfoVo) throws Exception {

		deviceInfoService.addDeviceInfo(dmsDeviceInfoVo);
		return Ret.ok();
	}


	/**
	 * 更新 DeviceInfo
	 * */
	@PutMapping("")
	public Ret updateDeviceInfo(@RequestBody DmsDeviceInfoVo dmsDeviceInfoVo) throws Exception {

		deviceInfoService.updateDeviceInfo(dmsDeviceInfoVo);
		return Ret.ok();
	}


	/**
	 * 删除 DeviceInfo
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveDeviceInfo( @RequestBody List<Long> ids ) throws Exception {

	    deviceInfoService.batchRemoveDeviceInfo(ids);
		return Ret.ok();
	}
}
